Skip to content

refactor: add import-linter baseline gate#38347

Draft
QuantumGhost wants to merge 12 commits into
langgenius:mainfrom
QuantumGhost:codex/import-linter-baseline-gate
Draft

refactor: add import-linter baseline gate#38347
QuantumGhost wants to merge 12 commits into
langgenius:mainfrom
QuantumGhost:codex/import-linter-baseline-gate

Conversation

@QuantumGhost

@QuantumGhost QuantumGhost commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

AI disclosure: This PR was primarily drafted with Codex using GPT-5.4. I have not reviewed and the final diff yet.

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

Fixes #38346.

This PR adds a small baseline gate around import-linter so layered-architecture refactors can be adopted incrementally in legacy backend packages.

  • add api/dev/lint_imports_baseline.py to convert broken import-linter contract metadata into a stable violation snapshot
  • compare the current snapshot against a committed baseline and fail when new violating edges are introduced
  • support both subset mode (default) and count mode, with subset used as the safer non-regression policy
  • add focused unit tests for snapshot extraction, comparison rules, and baseline write/read behavior
  • run the new gate from make lint via api-import-baseline-lint

Validation used for this change:

  • uv run --project api pytest api/tests/unit_tests/commands/test_lint_imports_baseline.py -q
  • uv run --project api --dev python api/dev/lint_imports_baseline.py --baseline api/dev/import_linter_baseline.json
  • uv run --project api --dev ruff check api/dev/lint_imports_baseline.py api/tests/unit_tests/commands/test_lint_imports_baseline.py

Screenshots

Before After
N/A N/A

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran make lint && make type-check (backend) and cd web && pnpm exec vp staged (frontend) to appease the lint gods

From Codex

Assisted-by: Codex:GPT-5.4
@QuantumGhost QuantumGhost added refactor python Pull requests that update python code area/backend labels Jul 2, 2026
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-07-02 18:12:18.924434600 +0000
+++ /tmp/pyrefly_pr.txt	2026-07-02 18:12:10.069319530 +0000
@@ -1,3 +1,9 @@
+ERROR Cannot set item in `dict[str, dict[str, set[str]]]` [unsupported-operation]
+  --> dev/lint_imports_baseline.py:74:39
+ERROR Returned type `dict[str, dict[str, set[str]]]` is not assignable to declared return type `dict[str, dict[str, list[str]]]` [bad-return]
+  --> dev/lint_imports_baseline.py:78:12
+ERROR Argument `DataclassInstance | type[DataclassInstance]` is not assignable to parameter `obj` with type `DataclassInstance` in function `dataclasses.asdict` [bad-argument-type]
+   --> dev/lint_imports_baseline.py:228:60
 ERROR Argument `SimpleNamespace` is not assignable to parameter `dataset` with type `Dataset` in function `dify_vdb_alibabacloud_mysql.alibabacloud_mysql_vector.AlibabaCloudMySQLVectorFactory.init_vector` [bad-argument-type]
   --> providers/vdb/vdb-alibabacloud-mysql/tests/unit_tests/test_alibabacloud_mysql_factory.py:42:38
 ERROR Argument `SimpleNamespace` is not assignable to parameter `dataset` with type `Dataset` in function `dify_vdb_alibabacloud_mysql.alibabacloud_mysql_vector.AlibabaCloudMySQLVectorFactory.init_vector` [bad-argument-type]

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 52.16% 52.16% -0.01%
Strict coverage 51.68% 51.67% -0.01%
Typed symbols 31,816 31,820 +4
Untyped symbols 29,452 29,462 +10
Modules 2953 2954 +1

@QuantumGhost QuantumGhost changed the title [codex] chore: add import-linter baseline gate refactor: add import-linter baseline gate Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/backend python Pull requests that update python code refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Refactor/Chore] Add a baseline gate for incremental import-linter adoption

1 participant